package kr.co.graviti.controller.pr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.co.graviti.common.application.MultipartUploadFileService;
import kr.co.graviti.common.model.MultipartUploadFile;
import kr.co.graviti.common.util.CommonPrSearchUtil;
import kr.co.graviti.common.util.CommonUtil;
import kr.co.graviti.common.util.CommonVariable;
import kr.co.graviti.common.util.PagingUtil;
import kr.co.graviti.service.cd.CdService;
import kr.co.graviti.service.cd.CdServiceImp;
import kr.co.graviti.service.pr.PRService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class PrController {
	
	@Autowired
	private CdService commService;
	@Autowired
	private PRService prService;
	
	@Resource
	private MultipartUploadFileService multipartUploadFileService;
	
	@Value("${common.default.upload.path}") private String uploadDefaultPath;
	@Value("${common.pr.upload.size}") private long uploadSize;
	@Value("${common.pr.upload.allow_postfix}") private String uploadAllowPostfix;
	@Value("${common.pr.upload.path}") private String detailPath;
	@Value("${common.action.nm}") private String extension;
	@Value("${common.default.download.path}") private String uploadfilepath;
	@Value("${common.pr.download.path}") private String prfilepath;
	
	/** PR 공통사용 > 서비스 관리 
	 * @param request
	 * @param response
	 * @param currentPage
	 * @param currentGroup
	 * @param searchnm
	 * @param searchword
	 * @return
	 */
	@RequestMapping(value="/pr/popPrService",method=RequestMethod.GET)
	public ModelAndView popPrService(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,
			@RequestParam(value="searchnm",required=false, defaultValue="") String searchnm,
			@RequestParam(value="searchword",required=false, defaultValue="") String searchword){
		
		HashMap<String, Object> param = new HashMap<String, Object>();
		if(request.getSession().getAttribute(CommonVariable.SESSION_LANG).equals("KOR")){
			param.put("cd_lst", "DC00000007");
		}else{
			param.put("cd_lst", "DC00000017");
		}
		
		param.put("currentPage", currentPage);
		param.put("currentGroup", currentGroup);
		
		String temp  = "";
		if(!CommonUtil.strNullChk(searchword).equals("")) param.put("searchword", "%"+searchword+"%");
		temp = CommonPrSearchUtil.prSearchNm(searchnm);
		param.put("searchnm", temp);
		param.put("startNum", CommonVariable.PAGE_PER_NAVIGATOR * (currentPage - 1));
		param.put("endNum", CommonVariable.PAGE_PER_NAVIGATOR);
		
		int totalCnt = commService.cdinfoTotalCnt(param);
		param.put("totArticle", totalCnt);
		param.put("qorder", " order by cast(cd as signed) desc");
		List<HashMap<String, Object>> list = commService.cdinfoPagingList(param);
		
		ModelAndView mav = new ModelAndView();
		mav.addObject("totalCnt",totalCnt);
		mav.setViewName(new String("pr/popPrService"));
		mav.addObject("paging", new PagingUtil(param).getPagingUtil());
		mav.addObject("currentPage", currentPage);
		mav.addObject("currentGroup", currentGroup);
		mav.addObject("searchword", searchword);
		mav.addObject("page_per_navigator", CommonVariable.PAGE_PER_NAVIGATOR);
		mav.addObject("list", list);
		return mav;
	}
	
	/** 서비스 관리 입력/수정/삭제 
	 * @param request
	 * @param response
	 * @param currentPage
	 * @param currentGroup
	 * @param searchnm
	 * @param searchword
	 * @param szMode
	 * @param addText
	 * @param cd
	 * @param updateText
	 * @return
	 */
	@RequestMapping(value="/pr/popPrService_proc",method=RequestMethod.POST)
	public ModelAndView popPrService_proc(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,
			@RequestParam(value="searchnm",required=false, defaultValue="") String searchnm,
			@RequestParam(value="searchword",required=false, defaultValue="") String searchword,
			@RequestParam(value="szMode",required=false, defaultValue="") String szMode,
			@RequestParam(value="addText",required=false, defaultValue="") String addText,
			@RequestParam(value="cd", required=true, defaultValue="1") Integer cd,
			@RequestParam(value="updateText", required=true, defaultValue="") String updateText){
		
		HashMap<String, Object> param = new HashMap<String, Object>();
		String cd_lst = "";
		if(request.getSession().getAttribute(CommonVariable.SESSION_LANG).equals("KOR")){
			cd_lst = "DC00000007";
		}else{
			cd_lst = "DC00000017";
		}
		param.put("cd_lst", cd_lst);
		
		if(!CommonUtil.strNullChk(searchword).equals("")) param.put("searchword", searchword);
		
		StringBuffer sb = new StringBuffer("redirect:");
		if(szMode.equals("write")){
			param.put("cd_nm", addText);
			commService.cdInsert(param);
			
		}else if(szMode.equals("modify")){
			param.put("cd", cd);
			param.put("cd_nm", updateText);
			commService.cdUpdate(param);
		}else if(szMode.equals("delete")){
			param.put("cd", cd);
			commService.cdDelete(param);
		}
		sb.append("/pr/popPrService"+extension);
		sb.append("?page="+currentPage);
		sb.append("&group="+currentGroup);
		sb.append("&searchnm="+searchnm);
		sb.append("&searchword="+searchword);
		return new ModelAndView(sb.toString());	
	}
	
	
	/** pop공통 켐페인 관리 
	 * @param request
	 * @param response
	 * @param currentPage
	 * @param currentGroup
	 * @param searchnm
	 * @param searchword
	 * @return
	 */
	@RequestMapping(value="/pr/popPrCampaign",method=RequestMethod.GET)
	public ModelAndView popPrCampaign(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,
			@RequestParam(value="searchnm",required=false, defaultValue="") String searchnm,
			@RequestParam(value="searchword",required=false, defaultValue="") String searchword){
		
		HashMap<String, Object> param = new HashMap<String, Object>();
				
		if(request.getSession().getAttribute(CommonVariable.SESSION_LANG).equals("KOR")){
			param.put("cd_lst", "DC00000008");
		}else{
			param.put("cd_lst", "DC00000018");
		}
		
		param.put("currentPage", currentPage);
		param.put("currentGroup", currentGroup);
		
		String temp  = "";
		if(!CommonUtil.strNullChk(searchword).equals("")) param.put("searchword", "%"+searchword+"%");
		temp = CommonPrSearchUtil.prSearchNm(searchnm);
		param.put("searchnm", temp);
		param.put("startNum", CommonVariable.PAGE_PER_NAVIGATOR * (currentPage - 1));
		param.put("endNum", CommonVariable.PAGE_PER_NAVIGATOR);
		
		int totalCnt = commService.cdinfoTotalCnt(param);
		param.put("totArticle", totalCnt);
		param.put("qorder", " order by cast(cd as signed) desc");
		List<HashMap<String, Object>> list = commService.cdinfoPagingList(param);
		
		ModelAndView mav = new ModelAndView();
		mav.addObject("totalCnt",totalCnt);
		mav.setViewName(new String("pr/popPrCampaign"));
		mav.addObject("paging", new PagingUtil(param).getPagingUtil());
		mav.addObject("currentPage", currentPage);
		mav.addObject("currentGroup", currentGroup);
		mav.addObject("searchword", searchword);
		mav.addObject("page_per_navigator", CommonVariable.PAGE_PER_NAVIGATOR);
		mav.addObject("list", list);
		return mav;
	}
	
	
	/** pop공통 켐페인 관리  > 입력,수정,삭제 
	 * @param request
	 * @param response
	 * @param currentPage
	 * @param currentGroup
	 * @param searchnm
	 * @param searchword
	 * @param szMode
	 * @param addText
	 * @param cd
	 * @param updateText
	 * @return
	 */
	@RequestMapping(value="/pr/popPrCampaign_proc",method=RequestMethod.POST)
	public ModelAndView popPrCampaign_proc(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,
			@RequestParam(value="searchnm",required=false, defaultValue="") String searchnm,
			@RequestParam(value="searchword",required=false, defaultValue="") String searchword,
			@RequestParam(value="szMode",required=false, defaultValue="") String szMode,
			@RequestParam(value="addText",required=false, defaultValue="") String addText,
			@RequestParam(value="cd", required=true, defaultValue="1") Integer cd,
			@RequestParam(value="updateText", required=true, defaultValue="") String updateText){
		
		HashMap<String, Object> param = new HashMap<String, Object>();
		String cd_lst = "";
		
		if(request.getSession().getAttribute(CommonVariable.SESSION_LANG).equals("KOR")){
			cd_lst = "DC00000008";
		}else{
			cd_lst = "DC00000018";
		}
		param.put("cd_lst", cd_lst);
		if(!CommonUtil.strNullChk(searchword).equals("")) param.put("searchword", searchword);
		StringBuffer sb = new StringBuffer("redirect:");
		if(szMode.equals("write")){
			param.put("cd_nm", addText);
			commService.cdInsert(param);			
		}else if(szMode.equals("modify")){
			param.put("cd", cd);
			param.put("cd_nm", updateText);
			commService.cdUpdate(param);
		}else if(szMode.equals("delete")){
			param.put("cd", cd);
			commService.cdDelete(param);
		}
		sb.append("/pr/popPrCampaign"+extension);
		sb.append("?page="+currentPage);
		sb.append("&group="+currentGroup);
		sb.append("&searchnm="+searchnm);
		sb.append("&searchword="+searchword);
		return new ModelAndView(sb.toString());	
	}
	
	/** 보도자료 List
	 * @param request
	 * @param response
	 * @param type
	 * @param currentPage
	 * @param currentGroup
	 * @return
	 */
	@RequestMapping(value="/pr/info_list")
	public ModelAndView info_list(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup){
		
		HashMap<String, Object> param = new HashMap<String, Object>();
		String board_cd = CommonVariable.BOARD_CD_BODO;
		param.put("board_cd", board_cd);
		param.put("lang", request.getSession().getAttribute(CommonVariable.SESSION_LANG));
		param.put("currentPage", currentPage);
		param.put("currentGroup", currentGroup);
		param.put("startNum", CommonVariable.PAGE_PER_NAVIGATOR * (currentPage - 1));
		param.put("endNum", CommonVariable.PAGE_PER_NAVIGATOR);
		int totalCnt = prService.totalcnt(param);
		param.put("totArticle", totalCnt);
		param.put("qorder", " order by board_idx desc ");
		List<HashMap<String, Object>> list = prService.boardPagingList(param);
		
		
		
		ModelAndView mav = new ModelAndView();
		
		mav.addObject("totalCnt",totalCnt);
		mav.setViewName(new String("pr/info_list"));
		mav.addObject("paging", new PagingUtil(param).getPagingUtil());
		mav.addObject("currentPage", currentPage);
		mav.addObject("currentGroup", currentGroup);
		mav.addObject("page_per_navigator", CommonVariable.PAGE_PER_NAVIGATOR);
		mav.addObject("list", list);
		return mav;			
	}
	
	/** 보도자료 입력/수정 
	 * @param request
	 * @param response
	 * @param currentPage
	 * @param currentGroup
	 * @param type
	 * @param szMode
	 * @param idx
	 * @return
	 */
	@RequestMapping(value="/pr/info_edit")
	public ModelAndView info_edit(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,
			@RequestParam(value="type",required=false, defaultValue="") String type,
			@RequestParam(value="szMode",required=false, defaultValue="") String szMode,
//			@RequestParam(value="USERID",required=false, defaultValue="") String USERID,
//			@RequestParam(value="USERNM",required=false, defaultValue="") String USERNM,
//			@RequestParam(value="top_notice_YN",required=false, defaultValue="") String top_notice_YN,
//			@RequestParam(value="sbjt",required=false, defaultValue="") String sbjt,
//			@RequestParam(value="ulfile",required=false, defaultValue="") String ulfile,
			@RequestParam(value="idx",required=false, defaultValue="0") String idx){
		
		HashMap<String, Object> viewer	= new HashMap<String, Object>();
		HashMap<String, Object> param = new HashMap<String, Object>();
		List<HashMap<String, Object>> fileList = null;
		
		if(szMode.equals("modify")){
			param.put("boardidx", idx);
			viewer = prService.boardView(param);
			param.put("ATTCH_FILE_IDX", viewer.get("attch_file_idx"));
			fileList = commService.fileselect(param);		
		}
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName(new String("pr/info_edit"));
		mav.addObject("uploadfilepath", uploadfilepath);
		mav.addObject("prfilepath", prfilepath);
		mav.addObject("today", CommonUtil.getDate() );
		if(szMode.equals("modify")){
			mav.addObject("viewer", viewer);
			mav.addObject("fileList", fileList);
		}
		mav.addObject("SESSION_ADMIN_NM", request.getSession().getAttribute(CommonVariable.SESSION_ADMIN_NM));
		return mav;
	}
	
	/**
	 * 멀티 첨부파일 디비정보 set
	 * @param multipartUploadFiles
	 * @param param
	 * @return
	 */
	public HashMap<String, Object> setFileInfoParameter(MultipartUploadFile multipartUploadFiles
			, HashMap<String, Object> param) {
		
		if (!CommonUtil.strNullChk(multipartUploadFiles.getFilename()).equals("")) {
			param.put("org_filenm", multipartUploadFiles.getOrginalFilename());
			param.put("chg_filenm", multipartUploadFiles.getFilename());
			param.put("file_size", multipartUploadFiles.getFilesize());
			param.put("filetype_cd", CommonUtil.getFileTypeCd(multipartUploadFiles.getContentType()));
		}
			
		return param;
	}
	
	/** 보도자료 입력/수정/삭제 
	 * @param request
	 * @param response
	 * @param top_mn_cd
	 * @param szMode
	 * @param type
	 * @param idx
	 * @param currentPage
	 * @param currentGroup
	 * @param attch_file_info_idx
	 * @param attch_file_idx
	 * @param parent_board_idx
	 * @param thread_idx
	 * @param depth
	 * @param ulfile
	 * @param sbjt
	 * @param cnts
	 * @param related_date
	 * @param post_end_date
	 * @param post_start_date
	 * @param top_notice_YN
	 * @param userid
	 * @param etc01
	 * @param etc02
	 * @param etc03
	 * @param writer_ip
	 * @param show_yn
	 * @return
	 */
	@RequestMapping(value="/pr/info_proc",method=RequestMethod.POST)
	public ModelAndView info_proc(HttpServletRequest request,
			HttpServletResponse response,
			MultipartHttpServletRequest multipartRequest,
			@RequestParam(value="top_mn_cd",required=false, defaultValue="") String top_mn_cd,
			@RequestParam(value="szMode",required=false, defaultValue="") String szMode,
			@RequestParam(value="type",required=false, defaultValue="") String type,
			@RequestParam(value="idx",required=false, defaultValue="") String idx,				
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,	
			@RequestParam(value="attch_file_info_idx",required=false, defaultValue="0") Integer attch_file_info_idx,
			@RequestParam(value="attch_file_idx",required=false, defaultValue="0") Integer _attch_file_idx,
			@RequestParam(value="parent_board_idx",required=false, defaultValue="0") String parent_board_idx,
			@RequestParam(value="thread_idx",required=false, defaultValue="0") String thread_idx,
			@RequestParam(value="depth",required=false, defaultValue="0") String depth,
//			@RequestParam(value="upfile02", required=false,defaultValue="") MultipartFile upfile02,
			@RequestParam(value="sbjt",required=false, defaultValue="") String sbjt,
			@RequestParam(value="cnts",required=false, defaultValue="") String cnts,
			@RequestParam(value="top_notice_YN",required=false,defaultValue="") String top_notice_YN,
			@RequestParam(value="delfile",required=false,defaultValue="") String delfile){
		
		System.out.println("info_proc==============================================AAA<");
		
		Iterator<String> iter = multipartRequest.getFileNames();
		while (iter.hasNext()) {
			System.out.println(iter.next());
		}
		
/* modify source start */
		
		MultipartUploadFile[] multipartUploadFiles = null;
		List<MultipartFile> fileList = new ArrayList<MultipartFile>();
		
		try {
			
			fileList = multipartRequest.getFiles("upfile02");
			for (MultipartFile item : fileList) {
				System.out.println(item.getOriginalFilename());
			}
			System.out.println(fileList.size());
			
			multipartUploadFiles = multipartUploadFileService.regist("pr"
					, uploadDefaultPath + detailPath
					, uploadSize
					, uploadAllowPostfix
					, fileList);	
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		int board_idx = 0;
		int attch_file_idx = 0;
		
/* modify source end */
		
		
		String fileorgNm = "",filesavNm = "";
		String board_cd = CommonVariable.BOARD_CD_BODO;
		long filesize = 0;
		

		HashMap<String, Object> param = new HashMap<String, Object>();
		
		param.put("filetype_cd", "3");
		param.put("lang", request.getSession().getAttribute(CommonVariable.SESSION_LANG));
		param.put("board_cd", board_cd);
		param.put("sbjt", sbjt);
		param.put("cnts", cnts);
		param.put("top_notice_YN", top_notice_YN);
		param.put("depth", depth);
		param.put("thread_idx", thread_idx);
		param.put("userid", request.getSession().getAttribute(CommonVariable.SESSION_ADMIN_ID));
		param.put("writer_ip", request.getRemoteAddr());
		
		// Return URL
		StringBuffer sb = new StringBuffer("redirect:");
		
		if(szMode.equals("write")){
			
			commService.commInsert();
			attch_file_idx	= commService.selectCommIdx();
			param.put("attch_file_idx", attch_file_idx);

/* modify source start */
			
			for (int i = 0; i < fileList.size(); i ++) {
				if (!CommonUtil.strNullChk(multipartUploadFiles[i].getFilename()).equals("")) {
					commService.fileInsert(setFileInfoParameter(multipartUploadFiles[i], param));
				}
			}
			board_idx = prService.commBoard_insert(param);
			
			
/* modify source start */
			
			if(!CommonUtil.strNullChk(fileorgNm).equals("")){
				param.put("org_filenm", fileorgNm);
				param.put("chg_filenm", filesavNm);
				param.put("filetype_cd", "1");
				param.put("file_size", filesize);
				commService.fileInsert(param);
			}
			
			sb.append("/pr/info_list"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
			
			
		}else if(szMode.equals("modify")){
			
			param.put("board_idx", idx);
			param.put("attch_file_idx", _attch_file_idx);
			prService.commBoard_update(param);
			
			// 이미지 삭제 
			if(!CommonUtil.strNullChk(delfile).equals("")){
				HashMap<String, Object> fileparam = new HashMap<String, Object>();
				fileparam.put("attch_file_info_idx", delfile);
				commService.fileDelete(fileparam);
				attch_file_info_idx = 0;
			}
			
			if(!CommonUtil.strNullChk(fileorgNm).equals("")){
				param.put("attch_file_info_idx", attch_file_info_idx);
				param.put("org_filenm", fileorgNm);
				param.put("chg_filenm", filesavNm);
				param.put("filetype_cd", "1");
				param.put("file_size", filesize);
				
				// insert 
				if(attch_file_info_idx==0){
					commService.fileInsert(param);
				// update 
				}else{
					commService.fileUpdate(param);
				}
			}
			
			sb.append("/pr/info_edit"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&szMode="+szMode);
			sb.append("&idx="+idx);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
		}else if(szMode.equals("delete")){
			param.put("board_idx", idx);
			param.put("attch_file_info_idx", attch_file_info_idx);
			prService.commBoard_delete(param);
			commService.fileDelete(param);
			
			sb.append("/pr/info_list"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
		}
		return new ModelAndView(sb.toString());	
	}
	
	/** PR TV광고 리스트 
	 * @param request
	 * @param response
	 * @param campaign
	 * @param currentPage
	 * @param currentGroup
	 * @return
	 */
	@RequestMapping(value="/pr/pr_list")
	public ModelAndView pr_list(HttpServletRequest request,
				HttpServletResponse response,
				@RequestParam(value="campaign",required=false, defaultValue="") String campaign,
				@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
				@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup){
		
		HashMap<String, Object> param = new HashMap<String, Object>();
		HashMap<String, Object> cdparam = new HashMap<String, Object>();
		
		String cd_lst01 = "",cd_lst02 = "";
		if(request.getSession().getAttribute(CommonVariable.SESSION_LANG).equals("KOR")){
			cd_lst01 =  "DC00000007";
			cd_lst02 =  "DC00000008";
		}else{
			cd_lst01 =  "DC00000017";
			cd_lst02 =  "DC00000018";
		}
		
		cdparam = new CdServiceImp().commcd(cd_lst02, "", "order by cd desc");
		
		
		List<HashMap<String, Object>> cdList	= commService.selectCdList(cdparam);
		
		String board_cd = CommonVariable.BOARD_CD_TV_ADV;
		param.put("board_cd", board_cd);
		param.put("lang", request.getSession().getAttribute(CommonVariable.SESSION_LANG));
		param.put("currentPage", currentPage);
		param.put("currentGroup", currentGroup);
		param.put("campaign", campaign);
		param.put("startNum", CommonVariable.PAGE_PER_NAVIGATOR * (currentPage - 1));
		param.put("endNum", CommonVariable.PAGE_PER_NAVIGATOR);
		int totalCnt = prService.totalcnt(param);
		param.put("totArticle", totalCnt);
		param.put("qorder", " order by related_date desc,board_idx desc ");
		
		// cd Text 
		param.put("temp01", cd_lst01);
		param.put("temp02", cd_lst02);
		
		List<HashMap<String, Object>> list = prService.boardPagingList(param);
		
		ModelAndView mav = new ModelAndView();
		mav.addObject("totalCnt",totalCnt);
		mav.setViewName(new String("pr/info_list"));
		mav.addObject("paging", new PagingUtil(param).getPagingUtil());
		mav.addObject("currentPage", currentPage);
		mav.addObject("currentGroup", currentGroup);
		mav.addObject("uploadfilepath", uploadfilepath);;
		mav.addObject("prfilepath", prfilepath);
		mav.addObject("campaign", campaign);
		mav.addObject("page_per_navigator", CommonVariable.PAGE_PER_NAVIGATOR);
		mav.setViewName(new String("pr/pr_list"));
		mav.addObject("list", list);
		mav.addObject("cdList",cdList);
		
		return mav;			
	}
	
	/** PR TV광고 입력/수정 폼 
	 * @param request
	 * @param response
	 * @param currentPage
	 * @param currentGroup
	 * @param szMode
	 * @param campaign
	 * @param idx
	 * @return
	 */
	@RequestMapping(value="/pr/pr_edit")
	public ModelAndView pr_edit(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,
			@RequestParam(value="szMode",required=false, defaultValue="") String szMode,
			@RequestParam(value="campaign",required=false, defaultValue="") String campaign,
			@RequestParam(value="idx",required=false, defaultValue="0") String idx){
		
		HashMap<String, Object> viewer	= new HashMap<String, Object>();
		HashMap<String, Object> param = new HashMap<String, Object>();
		List<HashMap<String, Object>> fileList = null;
		
		String board_cd = CommonVariable.BOARD_CD_TV_ADV;
		param.put("board_cd", board_cd);
		
		String cd_lst01 = "",cd_lst02 = "";
		if(request.getSession().getAttribute(CommonVariable.SESSION_LANG).equals("KOR")){
			cd_lst01 =  "DC00000007";
			cd_lst02 =  "DC00000008";
		}else{
			cd_lst01 =  "DC00000017";
			cd_lst02 =  "DC00000018";
		}
		
		if(szMode.equals("modify")){
			param.put("boardidx", idx);
			param.put("temp01", cd_lst01);
			param.put("temp02", cd_lst02);
			viewer = prService.boardView(param);
			param.put("ATTCH_FILE_IDX", viewer.get("attch_file_idx"));
			fileList = commService.fileselect(param);	
		}
		
		ModelAndView mav = new ModelAndView();
		mav.addObject("uploadfilepath", uploadfilepath);;
		mav.addObject("prfilepath", prfilepath);
		mav.setViewName(new String("pr/pr_edit"));
		if(szMode.equals("modify")){
			mav.addObject("viewer", viewer);
			mav.addObject("fileList", fileList);
		}
		mav.addObject("today", CommonUtil.getDate() );
		mav.addObject("file_type_thum01",CommonVariable.FILE_TYPE_CD_IMAGE);
		mav.addObject("file_type_thum02",CommonVariable.FILE_TYPE_CD_THUMNAIL);
		return mav;
	}
	
	/** PR TV광고 저장/수정/삭제 
	 * @param request
	 * @param response
	 * @param top_mn_cd
	 * @param campaign
	 * @param szMode
	 * @param idx
	 * @param currentPage
	 * @param currentGroup
	 * @param attch_file_info_idx
	 * @param attch_file_idx
	 * @param parent_board_idx
	 * @param thread_idx
	 * @param depth
	 * @param ulfile
	 * @param sbjt
	 * @param cnts
	 * @param related_date
	 * @param post_end_date
	 * @param post_start_date
	 * @param top_notice_YN
	 * @param userid
	 * @param etc01
	 * @param etc02
	 * @param etc03
	 * @param writer_ip
	 * @param show_yn
	 * @return
	 */
	@RequestMapping(value="/pr/pr_proc",method=RequestMethod.POST)
	public ModelAndView pr_proc(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="top_mn_cd",required=false, defaultValue="") String top_mn_cd,
			@RequestParam(value="campaign",required=false, defaultValue="") String campaign,
			@RequestParam(value="szMode",required=false, defaultValue="") String szMode,
			@RequestParam(value="idx",required=false, defaultValue="") String idx,				
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,	
			@RequestParam(value="attch_file_info_idx01",required=false, defaultValue="0") Integer attch_file_info_idx01,
			@RequestParam(value="attch_file_info_idx02",required=false, defaultValue="0") Integer attch_file_info_idx02,
			@RequestParam(value="attch_file_idx",required=false, defaultValue="0") Integer attch_file_idx,
			@RequestParam(value="parent_board_idx",required=false, defaultValue="0") String parent_board_idx,
			@RequestParam(value="thread_idx",required=false, defaultValue="0") String thread_idx,
			@RequestParam(value="depth",required=false, defaultValue="0") String depth,
			@RequestParam(value="ulfile", required=false,defaultValue="") MultipartFile ulfile,
			@RequestParam(value="upimg", required=false,defaultValue="") MultipartFile upimg,
			@RequestParam(value="sbjt",required=false, defaultValue="") String sbjt,
			@RequestParam(value="summary",required=false, defaultValue="") String summary,
			@RequestParam(value="cnts",required=false, defaultValue="") String cnts,
			@RequestParam(value="related_date",required=false, defaultValue="") String related_date,
			@RequestParam(value="post_end_date",required=false, defaultValue="") String post_end_date,
			@RequestParam(value="post_start_date",required=false, defaultValue="") String post_start_date,
			@RequestParam(value="top_notice_YN",required=false,defaultValue="") String top_notice_YN,
			@RequestParam(value="etc01",required=false,defaultValue="") String etc01,
			@RequestParam(value="etc02",required=false,defaultValue="") String etc02,
			@RequestParam(value="etc03",required=false,defaultValue="") String etc03,
			@RequestParam(value="etc04",required=false,defaultValue="") String etc04,
			@RequestParam(value="show_yn",required=false,defaultValue="") String show_yn){
		
		
		String fileorgNm01 = "",filesavNm01 = "",fileorgNm02 = "",filesavNm02 = "";
		String board_cd = CommonVariable.BOARD_CD_TV_ADV;
		long filesize01 = 0,filesize02 = 0;
		
		// 첨부파일 
		if(!ulfile.equals("")){
			
			MultipartUploadFile multipartUploadFile = new MultipartUploadFile();
			multipartUploadFile = multipartUploadFileService.regist("pr",uploadDefaultPath+detailPath
					, uploadSize
					, uploadAllowPostfix
					, ulfile);
			fileorgNm01	= multipartUploadFile.getOrginalFilename();
			filesavNm01	= multipartUploadFile.getFilename();
			filesize01	= multipartUploadFile.getFilesize();
		}
		
		// 첨부파일 
		if(!upimg.equals("")){
			
			MultipartUploadFile multipartUploadFile = new MultipartUploadFile();
			multipartUploadFile = multipartUploadFileService.regist("mobile_img",uploadDefaultPath+detailPath
					, uploadSize
					, uploadAllowPostfix
					, upimg);
			fileorgNm02	= multipartUploadFile.getOrginalFilename();
			filesavNm02	= multipartUploadFile.getFilename();
			filesize02	= multipartUploadFile.getFilesize();
		}
		
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("depth", depth);
		param.put("thread_idx", thread_idx);
		param.put("lang", request.getSession().getAttribute(CommonVariable.SESSION_LANG));
		param.put("sbjt", sbjt);
		param.put("summary", summary);
		param.put("cnts", cnts);
		param.put("related_date", related_date);
		param.put("top_notice_YN", top_notice_YN);
		param.put("show_yn", show_yn);
		param.put("etc01", etc01);
		param.put("etc02", etc02);
		param.put("etc03", etc03);
		param.put("etc04", etc04);
		param.put("board_cd", board_cd);
		param.put("userid", request.getSession().getAttribute(CommonVariable.SESSION_ADMIN_ID));
		param.put("writer_ip", request.getRemoteAddr());
		
		param.put("post_start_date", post_start_date);		// 게시일,종료일 NULL
		param.put("post_end_date", post_end_date);		// 게시일,종료일 NULL
		// Return URL
		StringBuffer sb = new StringBuffer("redirect:");
		if(szMode.equals("write")){
			commService.commInsert();
			attch_file_idx	= commService.selectCommIdx();
			param.put("attch_file_idx", attch_file_idx);
			prService.commBoard_insert(param);
			
			if(!CommonUtil.strNullChk(fileorgNm01).equals("")){
				param.put("org_filenm", fileorgNm01);
				param.put("chg_filenm", filesavNm01);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_IMAGE);
				param.put("file_size", filesize01);
				commService.fileInsert(param);
			}
			
			if(!CommonUtil.strNullChk(fileorgNm02).equals("")){
				param.put("org_filenm", fileorgNm02);
				param.put("chg_filenm", filesavNm02);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_THUMNAIL);
				param.put("file_size", filesize02);
				commService.fileInsert(param);
			}
			
			
			sb.append("/pr/pr_list"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
		}else if(szMode.equals("modify")){
			param.put("board_idx", idx);
			param.put("attch_file_idx", attch_file_idx);
			prService.commBoard_update(param);
			if(!CommonUtil.strNullChk(fileorgNm01).equals("")){
				param.put("attch_file_info_idx", attch_file_info_idx01);
				param.put("org_filenm", fileorgNm01);
				param.put("chg_filenm", filesavNm01);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_IMAGE);
				param.put("file_size", filesize01);
				
				// insert 
				if(attch_file_info_idx01==0){
					commService.fileInsert(param);
				// update 
				}else{
					commService.fileUpdate(param);
				}
			}
			
			if(!CommonUtil.strNullChk(fileorgNm02).equals("")){
				param.put("attch_file_info_idx", attch_file_info_idx02);
				param.put("org_filenm", fileorgNm02);
				param.put("chg_filenm", filesavNm02);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_THUMNAIL);
				param.put("file_size", filesize01);
				
				// insert 
				if(attch_file_info_idx02==0){
					commService.fileInsert(param);
				// update 
				}else{
					commService.fileUpdate(param);
				}
			}
			
			sb.append("/pr/pr_edit"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&szMode="+szMode);
			sb.append("&idx="+idx);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
			sb.append("&campaign="+campaign);
			
			
		}else if(szMode.equals("delete")){
			param.put("board_idx", idx);
			param.put("attch_file_info_idx", attch_file_info_idx01);
			prService.commBoard_delete(param);
			commService.fileDelete(param);
			param.put("attch_file_info_idx", attch_file_info_idx02);
			commService.fileDelete(param);
			
			sb.append("/pr/pr_list"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
			sb.append("&campaign="+campaign);
		}
		return new ModelAndView(sb.toString());	
	}
	
	/**  PR 인쇄광고 리스트 
	 * @param request
	 * @param response
	 * @param campaign
	 * @param currentPage
	 * @param currentGroup
	 * @return
	 */
	@RequestMapping(value="/pr/printPr_list")
	public ModelAndView printPr_list(HttpServletRequest request,
				HttpServletResponse response,
				@RequestParam(value="campaign",required=false, defaultValue="") String campaign,
				@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
				@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup){
		
		
		HashMap<String, Object> param = new HashMap<String, Object>();
		HashMap<String, Object> cdparam = new HashMap<String, Object>();
		String cd_lst01 = "",cd_lst02 = "";
		if(request.getSession().getAttribute(CommonVariable.SESSION_LANG).equals("KOR")){
			cd_lst01 =  "DC00000007";
			cd_lst02 =  "DC00000008";
		}else{
			cd_lst01 =  "DC00000017";
			cd_lst02 =  "DC00000018";
		}
		
		cdparam = new CdServiceImp().commcd(cd_lst02, "", "order by cd desc");
		List<HashMap<String, Object>> cdList	= commService.selectCdList(cdparam);
		
		String board_cd = CommonVariable.BOARD_CD_PRINT_ADV;
		param.put("board_cd", board_cd);
		param.put("lang", request.getSession().getAttribute(CommonVariable.SESSION_LANG));
		param.put("currentPage", currentPage);
		param.put("currentGroup", currentGroup);
		param.put("campaign", campaign);
		param.put("startNum", CommonVariable.PAGE_PER_NAVIGATOR * (currentPage - 1));
		param.put("endNum", CommonVariable.PAGE_PER_NAVIGATOR);
		int totalCnt = prService.totalcnt(param);
		param.put("totArticle", totalCnt);
		param.put("qorder", " order by related_date desc,board_idx desc ");
		
		// cd Text 
		param.put("temp01", cd_lst01);
		param.put("temp02", cd_lst02);
		
		List<HashMap<String, Object>> list = prService.boardPagingList(param);
		
		ModelAndView mav = new ModelAndView();
		mav.addObject("totalCnt",totalCnt);
		mav.setViewName(new String("pr/info_list"));
		mav.addObject("paging", new PagingUtil(param).getPagingUtil());
		mav.addObject("currentPage", currentPage);
		mav.addObject("currentGroup", currentGroup);
		mav.addObject("uploadfilepath", uploadfilepath);;
		mav.addObject("prfilepath", prfilepath);
		mav.addObject("campaign", campaign);
		mav.addObject("page_per_navigator", CommonVariable.PAGE_PER_NAVIGATOR);
		mav.setViewName(new String("pr/printPr_list"));
		mav.addObject("list", list);
		mav.addObject("cdList",cdList);
		
		return mav;			
	}
	
	@RequestMapping(value="/pr/printPr_edit")
	public ModelAndView printPr_edit(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,
			@RequestParam(value="szMode",required=false, defaultValue="") String szMode,
			@RequestParam(value="campaign",required=false, defaultValue="") String campaign,
			@RequestParam(value="idx",required=false, defaultValue="0") String idx){
		
		HashMap<String, Object> viewer	= new HashMap<String, Object>();
		HashMap<String, Object> param = new HashMap<String, Object>();
		List<HashMap<String, Object>> fileList = null;
		
		String board_cd = CommonVariable.BOARD_CD_PRINT_ADV;
		param.put("board_cd", board_cd);
		
		String cd_lst01 = "",cd_lst02 = "";
		if(request.getSession().getAttribute(CommonVariable.SESSION_LANG).equals("KOR")){
			cd_lst01 =  "DC00000007";
			cd_lst02 =  "DC00000008";
		}else{
			cd_lst01 =  "DC00000017";
			cd_lst02 =  "DC00000018";
		}
		
		if(szMode.equals("modify")){
			param.put("boardidx", idx);
			param.put("temp01", cd_lst01);
			param.put("temp02", cd_lst02);
			viewer = prService.boardView(param);
			param.put("ATTCH_FILE_IDX", viewer.get("attch_file_idx"));
			fileList = commService.fileselect(param);	
		}
		
		ModelAndView mav = new ModelAndView();
		mav.addObject("uploadfilepath", uploadfilepath);;
		mav.addObject("prfilepath", prfilepath);
		mav.setViewName(new String("pr/printPr_edit"));
		if(szMode.equals("modify")){
			mav.addObject("viewer", viewer);
			mav.addObject("fileList", fileList);
		}
		mav.addObject("today", CommonUtil.getDate() );
		mav.addObject("file_type_thum01",CommonVariable.FILE_TYPE_CD_IMAGE);
		mav.addObject("file_type_thum02",CommonVariable.FILE_TYPE_CD_THUMNAIL);
		mav.addObject("file_type_thum03",CommonVariable.FILE_TYPE_CD_BIGIMG);
		
		return mav;
	}
	
	@RequestMapping(value="/pr/printPr_proc",method=RequestMethod.POST)
	public ModelAndView printPr_proc(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="top_mn_cd",required=false, defaultValue="") String top_mn_cd,
			@RequestParam(value="campaign",required=false, defaultValue="") String campaign,
			@RequestParam(value="szMode",required=false, defaultValue="") String szMode,
			@RequestParam(value="idx",required=false, defaultValue="") String idx,				
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,	
			@RequestParam(value="attch_file_info_idx01",required=false, defaultValue="0") Integer attch_file_info_idx01,
			@RequestParam(value="attch_file_info_idx02",required=false, defaultValue="0") Integer attch_file_info_idx02,
			@RequestParam(value="attch_file_info_idx03",required=false, defaultValue="0") Integer attch_file_info_idx03,
			@RequestParam(value="attch_file_idx",required=false, defaultValue="0") Integer attch_file_idx,
			@RequestParam(value="parent_board_idx",required=false, defaultValue="0") String parent_board_idx,
			@RequestParam(value="thread_idx",required=false, defaultValue="0") String thread_idx,
			@RequestParam(value="depth",required=false, defaultValue="0") String depth,
			@RequestParam(value="ulfile", required=false,defaultValue="") MultipartFile ulfile,
			@RequestParam(value="upfile", required=false,defaultValue="") MultipartFile upfile,
			@RequestParam(value="upbigimg", required=false,defaultValue="") MultipartFile upbigimg,
			@RequestParam(value="sbjt",required=false, defaultValue="") String sbjt,
			@RequestParam(value="cnts",required=false, defaultValue="") String cnts,
			@RequestParam(value="summary",required=false, defaultValue="") String summary,
			@RequestParam(value="related_date",required=false, defaultValue="") String related_date,
			@RequestParam(value="post_end_date",required=false, defaultValue="") String post_end_date,
			@RequestParam(value="post_start_date",required=false, defaultValue="") String post_start_date,
			@RequestParam(value="top_notice_YN",required=false,defaultValue="") String top_notice_YN,
			@RequestParam(value="etc01",required=false,defaultValue="") String etc01,
			@RequestParam(value="etc02",required=false,defaultValue="") String etc02,
			@RequestParam(value="etc03",required=false,defaultValue="") String etc03,
			@RequestParam(value="show_yn",required=false,defaultValue="") String show_yn){
		
		String fileorgNm01 = "",filesavNm01 = "";
		String fileorgNm02 = "",filesavNm02 = "";
		String fileorgNm03 = "",filesavNm03 = "";
		String board_cd = CommonVariable.BOARD_CD_PRINT_ADV;
		long filesize01 = 0,filesize02 = 0,filesize03 = 0;
		
		// 첨부파일 (썸네일)
		if(!ulfile.equals("")){
			MultipartUploadFile multipartUploadFile = new MultipartUploadFile();
			multipartUploadFile = multipartUploadFileService.regist("thum",uploadDefaultPath+detailPath
					, uploadSize
					, uploadAllowPostfix
					, ulfile);
			fileorgNm01	= multipartUploadFile.getOrginalFilename();
			filesavNm01	= multipartUploadFile.getFilename();
			filesize01	= multipartUploadFile.getFilesize();
		}
		
		// 첨부파일 (원본 이미지)
		if(!upfile.equals("")){
			MultipartUploadFile multipartUploadFile = new MultipartUploadFile();
			multipartUploadFile = multipartUploadFileService.regist("img",uploadDefaultPath+detailPath
					, uploadSize
					, uploadAllowPostfix
					, upfile);
			fileorgNm02	= multipartUploadFile.getOrginalFilename();
			filesavNm02	= multipartUploadFile.getFilename();
			filesize02	= multipartUploadFile.getFilesize();
		}
		
		// 첨부파일 (원본 이미지)
		if(!upbigimg.equals("")){
			MultipartUploadFile multipartUploadFile = new MultipartUploadFile();
			multipartUploadFile = multipartUploadFileService.regist("big",uploadDefaultPath+detailPath
					, uploadSize
					, uploadAllowPostfix
					, upbigimg);
			fileorgNm03	= multipartUploadFile.getOrginalFilename();
			filesavNm03	= multipartUploadFile.getFilename();
			filesize03	= multipartUploadFile.getFilesize();
		}
		
		
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("depth", depth);
		param.put("thread_idx", thread_idx);
		param.put("lang", request.getSession().getAttribute(CommonVariable.SESSION_LANG));
		param.put("sbjt", sbjt);
		param.put("summary", summary);
		param.put("cnts", cnts);
		param.put("related_date", related_date);
		param.put("top_notice_YN", top_notice_YN);
		param.put("show_yn", show_yn);
		param.put("etc01", etc01);
		param.put("etc02", etc02);
		param.put("etc03", etc03);
		param.put("board_cd", board_cd);
		param.put("userid", request.getSession().getAttribute(CommonVariable.SESSION_ADMIN_ID));
		param.put("writer_ip", request.getRemoteAddr());
		
		param.put("post_start_date", post_start_date);		// 게시일,종료일 NULL
		param.put("post_end_date", post_end_date);		// 게시일,종료일 NULL
		// Return URL
		StringBuffer sb = new StringBuffer("redirect:");
		if(szMode.equals("write")){
			commService.commInsert();
			attch_file_idx	= commService.selectCommIdx();
			param.put("attch_file_idx", attch_file_idx);
			prService.commBoard_insert(param);
			
			if(!CommonUtil.strNullChk(fileorgNm01).equals("")){
				param.put("org_filenm", fileorgNm01);
				param.put("chg_filenm", filesavNm01);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_IMAGE);
				param.put("file_size", filesize01);
				commService.fileInsert(param);
			}
			
			if(!CommonUtil.strNullChk(fileorgNm02).equals("")){
				param.put("org_filenm", fileorgNm02);
				param.put("chg_filenm", filesavNm02);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_THUMNAIL);
				param.put("file_size", filesize02);
				commService.fileInsert(param);
			}
			
			if(!CommonUtil.strNullChk(fileorgNm03).equals("")){
				param.put("org_filenm", fileorgNm03);
				param.put("chg_filenm", filesavNm03);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_BIGIMG);
				param.put("file_size", filesize03);
				commService.fileInsert(param);
			}
			
			sb.append("/pr/printPr_list"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
		}else if(szMode.equals("modify")){
			param.put("board_idx", idx);
			param.put("attch_file_idx", attch_file_idx);
			prService.commBoard_update(param);
			
			if(!CommonUtil.strNullChk(fileorgNm01).equals("")){
				param.put("attch_file_info_idx", attch_file_info_idx01);
				param.put("org_filenm", fileorgNm01);
				param.put("chg_filenm", filesavNm01);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_IMAGE);
				param.put("file_size", filesize01);
				
				// insert 
				if(attch_file_info_idx01==0){
					commService.fileInsert(param);
				// update 
				}else{
					commService.fileUpdate(param);
				}
			}
			
			if(!CommonUtil.strNullChk(fileorgNm02).equals("")){
				param.put("attch_file_info_idx", attch_file_info_idx02);
				param.put("org_filenm", fileorgNm02);
				param.put("chg_filenm", filesavNm02);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_THUMNAIL);
				param.put("file_size", filesize02);
				
				// insert 
				if(attch_file_info_idx02==0){
					commService.fileInsert(param);
				// update 
				}else{
					commService.fileUpdate(param);
				}
			}
			
			if(!CommonUtil.strNullChk(fileorgNm03).equals("")){
				param.put("attch_file_info_idx", attch_file_info_idx03);
				param.put("org_filenm", fileorgNm03);
				param.put("chg_filenm", filesavNm03);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_BIGIMG);
				param.put("file_size", filesize03);
				
				// insert 
				if(attch_file_info_idx03==0){
					commService.fileInsert(param);
				// update 
				}else{
					commService.fileUpdate(param);
				}
			}
				
			sb.append("/pr/printPr_edit"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&szMode="+szMode);
			sb.append("&idx="+idx);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
			sb.append("&campaign="+campaign);
			
		}else if(szMode.equals("delete")){
			param.put("board_idx", idx);
			param.put("attch_file_info_idx", attch_file_info_idx01);
			prService.commBoard_delete(param);
			commService.fileDelete(param);
			param.remove("attch_file_info_idx");
			param.put("attch_file_info_idx", attch_file_info_idx02);
			commService.fileDelete(param);
			param.remove("attch_file_info_idx");
			param.put("attch_file_info_idx", attch_file_info_idx03);
			commService.fileDelete(param);
			
			sb.append("/pr/printPr_list"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
			sb.append("&campaign="+campaign);
		}
		return new ModelAndView(sb.toString());	
	}
	
	/** PR 영상 목록 
	 * @param request
	 * @param response
	 * @param campaign
	 * @param currentPage
	 * @param currentGroup
	 * @return
	 */
	@RequestMapping(value="/pr/prVideo_list")
	public ModelAndView prVideo_list(HttpServletRequest request,
				HttpServletResponse response,
				@RequestParam(value="campaign",required=false, defaultValue="") String campaign,
				@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
				@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup){
		
		HashMap<String, Object> param = new HashMap<String, Object>();
		HashMap<String, Object> cdparam = new HashMap<String, Object>();
		String cd_lst01 = "",cd_lst02 = "";
		if(request.getSession().getAttribute(CommonVariable.SESSION_LANG).equals("KOR")){
			cd_lst01 =  "DC00000007";
			cd_lst02 =  "DC00000008";
		}else{
			cd_lst01 =  "DC00000017";
			cd_lst02 =  "DC00000018";
		}
		
		cdparam = new CdServiceImp().commcd(cd_lst02, "", "order by cd desc");
		List<HashMap<String, Object>> cdList	= commService.selectCdList(cdparam);
		
		String board_cd = CommonVariable.BOARD_CD_PR;
		param.put("board_cd", board_cd);
		param.put("currentPage", currentPage);
		param.put("currentGroup", currentGroup);
		param.put("lang", request.getSession().getAttribute(CommonVariable.SESSION_LANG));
		param.put("campaign", campaign);
		param.put("startNum", CommonVariable.PAGE_PER_NAVIGATOR * (currentPage - 1));
		param.put("endNum", CommonVariable.PAGE_PER_NAVIGATOR);
		int totalCnt = prService.totalcnt(param);
		param.put("totArticle", totalCnt);
		param.put("qorder", " order by related_date desc,board_idx desc ");
		
		// cd Text 
		param.put("temp01", cd_lst01);
		param.put("temp02", cd_lst02);
		
		List<HashMap<String, Object>> list = prService.boardPagingList(param);
		
		ModelAndView mav = new ModelAndView();
		mav.addObject("uploadfilepath", uploadfilepath);;
		mav.addObject("prfilepath", prfilepath);
		mav.addObject("totalCnt",totalCnt);
		mav.setViewName(new String("pr/info_list"));
		mav.addObject("uploadfilepath", uploadfilepath);;
		mav.addObject("prfilepath", prfilepath);
		mav.addObject("paging", new PagingUtil(param).getPagingUtil());
		mav.addObject("currentPage", currentPage);
		mav.addObject("currentGroup", currentGroup);
		mav.addObject("campaign", campaign);
		mav.addObject("page_per_navigator", CommonVariable.PAGE_PER_NAVIGATOR);
		mav.setViewName(new String("pr/prVideo_list"));
		mav.addObject("list", list);
		mav.addObject("cdList",cdList);
		
		return mav;			
	}
	
	
	/** PR 영상 입력/수정 
	 * @param request
	 * @param response
	 * @param currentPage
	 * @param currentGroup
	 * @param szMode
	 * @param campaign
	 * @param idx
	 * @return
	 */
	@RequestMapping(value="/pr/prVideo_edit")
	public ModelAndView prVideo_edit(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,
			@RequestParam(value="szMode",required=false, defaultValue="") String szMode,
			@RequestParam(value="campaign",required=false, defaultValue="") String campaign,
			@RequestParam(value="idx",required=false, defaultValue="0") String idx){
		
		HashMap<String, Object> viewer	= new HashMap<String, Object>();
		HashMap<String, Object> param = new HashMap<String, Object>();
		List<HashMap<String, Object>> fileList = null;
		
		String board_cd = CommonVariable.BOARD_CD_PR;
		param.put("board_cd", board_cd);
		String cd_lst01 = "",cd_lst02 = "";
		if(request.getSession().getAttribute(CommonVariable.SESSION_LANG).equals("KOR")){
			cd_lst01 =  "DC00000007";
			cd_lst02 =  "DC00000008";
		}else{
			cd_lst01 =  "DC00000017";
			cd_lst02 =  "DC00000018";
		}
		
		if(szMode.equals("modify")){
			param.put("boardidx", idx);
			param.put("temp01", cd_lst01);
			param.put("temp02", cd_lst02);
			viewer = prService.boardView(param);
			param.put("ATTCH_FILE_IDX", viewer.get("attch_file_idx"));
			fileList = commService.fileselect(param);	
		}
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName(new String("pr/prVideo_edit"));
		mav.addObject("uploadfilepath", uploadfilepath);;
		mav.addObject("prfilepath", prfilepath);
		if(szMode.equals("modify")){
			mav.addObject("viewer", viewer);
			mav.addObject("fileList", fileList);
		}
		mav.addObject("file_type_thum01",CommonVariable.FILE_TYPE_CD_IMAGE);
		mav.addObject("file_type_thum02",CommonVariable.FILE_TYPE_CD_THUMNAIL);
		mav.addObject("today", CommonUtil.getDate() );
		return mav;
	}
	
	/** PR 영상 입력/수정/삭제 
	 * @param request
	 * @param response
	 * @param top_mn_cd
	 * @param campaign
	 * @param szMode
	 * @param idx
	 * @param currentPage
	 * @param currentGroup
	 * @param attch_file_info_idx
	 * @param attch_file_idx
	 * @param parent_board_idx
	 * @param thread_idx
	 * @param depth
	 * @param ulfile
	 * @param sbjt
	 * @param cnts
	 * @param related_date
	 * @param post_end_date
	 * @param post_start_date
	 * @param top_notice_YN
	 * @param userid
	 * @param etc01
	 * @param etc02
	 * @param etc03
	 * @param writer_ip
	 * @param show_yn
	 * @return
	 */
	@RequestMapping(value="/pr/prVideo_proc",method=RequestMethod.POST)
	public ModelAndView prVideo_proc(HttpServletRequest request,
			HttpServletResponse response,
			@RequestParam(value="top_mn_cd",required=false, defaultValue="") String top_mn_cd,
			@RequestParam(value="campaign",required=false, defaultValue="") String campaign,
			@RequestParam(value="szMode",required=false, defaultValue="") String szMode,
			@RequestParam(value="idx",required=false, defaultValue="") String idx,				
			@RequestParam(value="page", required=true, defaultValue="1") Integer currentPage,
			@RequestParam(value="group", required=true, defaultValue="1") Integer currentGroup,	
			@RequestParam(value="attch_file_info_idx01",required=false, defaultValue="0") Integer attch_file_info_idx01,
			@RequestParam(value="attch_file_info_idx02",required=false, defaultValue="0") Integer attch_file_info_idx02,
			@RequestParam(value="attch_file_idx",required=false, defaultValue="0") Integer attch_file_idx,
			@RequestParam(value="parent_board_idx",required=false, defaultValue="0") String parent_board_idx,
			@RequestParam(value="thread_idx",required=false, defaultValue="0") String thread_idx,
			@RequestParam(value="depth",required=false, defaultValue="0") String depth,
			@RequestParam(value="ulfile", required=false,defaultValue="") MultipartFile ulfile,
			@RequestParam(value="upimg", required=false,defaultValue="") MultipartFile upimg,
			@RequestParam(value="sbjt",required=false, defaultValue="") String sbjt,
			@RequestParam(value="summary",required=false, defaultValue="") String summary,
			@RequestParam(value="cnts",required=false, defaultValue="") String cnts,
			@RequestParam(value="related_date",required=false, defaultValue="") String related_date,
			@RequestParam(value="post_end_date",required=false, defaultValue="") String post_end_date,
			@RequestParam(value="post_start_date",required=false, defaultValue="") String post_start_date,
			@RequestParam(value="top_notice_YN",required=false,defaultValue="") String top_notice_YN,
			@RequestParam(value="etc01",required=false,defaultValue="") String etc01,
			@RequestParam(value="etc02",required=false,defaultValue="") String etc02,
			@RequestParam(value="etc03",required=false,defaultValue="") String etc03,
			@RequestParam(value="etc04",required=false,defaultValue="") String etc04,
			@RequestParam(value="show_yn",required=false,defaultValue="") String show_yn){
		
		
		String fileorgNm01 = "",filesavNm01 = "",fileorgNm02 = "",filesavNm02 = "";
		String board_cd = CommonVariable.BOARD_CD_PR;
		long filesize01 = 0,filesize02 = 0;
		
		// 첨부파일 
		if(!ulfile.equals("")){
			
			MultipartUploadFile multipartUploadFile = new MultipartUploadFile();
			multipartUploadFile = multipartUploadFileService.regist("pr",uploadDefaultPath+detailPath
					, uploadSize
					, uploadAllowPostfix
					, ulfile);
			fileorgNm01	= multipartUploadFile.getOrginalFilename();
			filesavNm01	= multipartUploadFile.getFilename();
			filesize01	= multipartUploadFile.getFilesize();
		}
		
		// 첨부파일 
		if(!upimg.equals("")){
			MultipartUploadFile multipartUploadFile = new MultipartUploadFile();
			multipartUploadFile = multipartUploadFileService.regist("mobile_img",uploadDefaultPath+detailPath
					, uploadSize
					, uploadAllowPostfix
					, upimg);
			fileorgNm02	= multipartUploadFile.getOrginalFilename();
			filesavNm02	= multipartUploadFile.getFilename();
			filesize02	= multipartUploadFile.getFilesize();
		}
		
		HashMap<String, Object> param = new HashMap<String, Object>();
		param.put("depth", depth);
		param.put("thread_idx", thread_idx);
		param.put("lang", request.getSession().getAttribute(CommonVariable.SESSION_LANG));
		param.put("sbjt", sbjt);
		param.put("cnts", cnts);
		param.put("summary", summary);
		param.put("related_date", related_date);
		param.put("top_notice_YN", top_notice_YN);
		param.put("show_yn", show_yn);
		param.put("etc01", etc01);
		param.put("etc02", etc02);
		param.put("etc03", etc03);
		param.put("etc04", etc04);
		param.put("board_cd", board_cd);
		param.put("userid", request.getSession().getAttribute(CommonVariable.SESSION_ADMIN_ID));
		param.put("writer_ip", request.getRemoteAddr());
		
		param.put("post_start_date", post_start_date);		// 게시일,종료일 NULL
		param.put("post_end_date", post_end_date);		// 게시일,종료일 NULL
		// Return URL
		StringBuffer sb = new StringBuffer("redirect:");
		if(szMode.equals("write")){
			commService.commInsert();
			attch_file_idx	= commService.selectCommIdx();
			param.put("attch_file_idx", attch_file_idx);
			prService.commBoard_insert(param);
			
			if(!CommonUtil.strNullChk(fileorgNm01).equals("")){
				param.put("org_filenm", fileorgNm01);
				param.put("chg_filenm", filesavNm01);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_IMAGE);
				param.put("file_size", filesize01);
				commService.fileInsert(param);
			}
			
			if(!CommonUtil.strNullChk(fileorgNm02).equals("")){
				param.put("org_filenm", fileorgNm02);
				param.put("chg_filenm", filesavNm02);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_THUMNAIL);
				param.put("file_size", filesize02);
				commService.fileInsert(param);
			}
			
			sb.append("/pr/prVideo_list"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
		}else if(szMode.equals("modify")){
			param.put("board_idx", idx);
			param.put("attch_file_idx", attch_file_idx);
			prService.commBoard_update(param);
			
			if(!CommonUtil.strNullChk(fileorgNm01).equals("")){
				param.put("attch_file_info_idx", attch_file_info_idx01);
				param.put("org_filenm", fileorgNm01);
				param.put("chg_filenm", filesavNm01);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_IMAGE);
				param.put("file_size", filesize01);
				
				// insert 
				if(attch_file_info_idx01==0){
					commService.fileInsert(param);
				// update 
				}else{
					commService.fileUpdate(param);
				}
			}

			if(!CommonUtil.strNullChk(fileorgNm02).equals("")){
				param.put("attch_file_info_idx", attch_file_info_idx01);
				param.put("org_filenm", fileorgNm02);
				param.put("chg_filenm", filesavNm02);
				param.put("filetype_cd", CommonVariable.FILE_TYPE_CD_THUMNAIL);
				param.put("file_size", filesize02);
				
				// insert 
				if(attch_file_info_idx02==0){
					commService.fileInsert(param);
				// update 
				}else{
					commService.fileUpdate(param);
				}
			}
			sb.append("/pr/prVideo_edit"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&szMode="+szMode);
			sb.append("&idx="+idx);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
			sb.append("&campaign="+campaign);
			 
		}else if(szMode.equals("delete")){
			param.put("board_idx", idx);
			param.put("attch_file_info_idx", attch_file_info_idx01);
			prService.commBoard_delete(param);
			commService.fileDelete(param);
			param.put("attch_file_info_idx", attch_file_info_idx02);
			commService.fileDelete(param);
			
			sb.append("/pr/prVideo_list"+extension);
			sb.append("?top_mn_cd="+top_mn_cd);
			sb.append("&page="+currentPage);
			sb.append("&group="+currentGroup);
			sb.append("&campaign="+campaign);
		}
		return new ModelAndView(sb.toString());	
	}
}